package io.gitee.zicai.graphql.sample.self;

import com.google.common.collect.Lists;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.impl.JPAQueryFactory;
import io.gitee.zicai.graphql.sample.dao.IBaseRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;

import java.util.List;

/**
 * GraphQLBaseDataFetcher
 *
 * @author zicai
 * @since 2021-04-13
 */
public class GraphQLBaseDataFetcher<R extends IBaseRepo<T, ID>, T, ID> {

    @Autowired
    protected JPAQueryFactory dsl;
    @Autowired
    protected R dao;

    public List<T> findAll(Predicate predicate) {
        return Lists.newArrayList(dao.findAll(predicate));
    }

    public List<T> findAll(Predicate predicate, Sort sort) {
        return Lists.newArrayList(dao.findAll(predicate, sort));
    }

    public List<T> findAll(Predicate predicate, OrderSpecifier<?>... orderSpecifiers) {
        return Lists.newArrayList(dao.findAll(predicate, orderSpecifiers));
    }

    public List<T> findAll(OrderSpecifier<?>... orderSpecifiers) {
        return Lists.newArrayList(dao.findAll(orderSpecifiers));
    }
}
